﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interpreter.TableBuilder
{
	internal class FloatTableBuilder
	{
		public static double[] GetTable(string rawTable)
		{
			string[] t;
			int exp;
			double baseValue;
			string[] entries = Util.SmartSplit(rawTable, '|');
			double[] output = new double[entries.Length];
			double value;
			for (int i = 0; i < output.Length; ++i)
			{
				if (entries[i] == "0")
				{
					value = 0;
				}
				else
				{
					t = entries[i].Split('E');
					if (t.Length != 2 ||
						!int.TryParse(t[1], out exp) || 
						!double.TryParse(t[0], out baseValue))
					{
						throw new Exception("Corrupted float table.");
					}

					value = baseValue * Math.Pow(10, exp);
				}

				output[i] = value;
			}

			return output;
		}
	}
}
